package fr.ul.ade.prime.provider;

import android.content.ContentUris;
import android.net.Uri;
import android.provider.BaseColumns;

/**
 * @author Schnell Michaël, Zanette Sébastien
 * @version 1.0
 */
public final class AdeWebContract {

	public static final String CONTENT_AUTHORITY = "fr.ul.ade"; //$NON-NLS-1$

	public static final Uri BASE_CONTENT_URI = Uri
			.parse("content://" + CONTENT_AUTHORITY); //$NON-NLS-1$

	public static final String PATH_SCHEDULE = "schedule"; //$NON-NLS-1$
	public static final String PATH_LESSON = "lesson"; //$NON-NLS-1$
	public static final String PATH_PROJECT = "project"; //$NON-NLS-1$
	public static final String PATH_STUDENT_NUMBER = "student_number"; //$NON-NLS-1$

	public static final String PATH_BETWEEN = "between"; //$NON-NLS-1$

	private AdeWebContract() {
	}

	interface ScheduleColumns {
		String SCHEDULE_NAME = "name"; //$NON-NLS-1$
		String SCHEDULE_PROJECT_ID = "project"; //$NON-NLS-1$
		String SCHEDULE_ADE_PROJECT_ID = "project_id"; //$NON-NLS-1$
		String SCHEDULE_PROJECT_NAME = "project_name"; //$NON-NLS-1$
		String SCHEDULE_RESOURCES = "resources"; //$NON-NLS-1$
		String SCHEDULE_STUDENT_NUM = "student_numbers"; //$NON-NLS-1$
		String SCHEDULE_ALL_RESOURCES = "all_resources"; //$NON-NLS-1$
		String SCHEDULE_PERIOD = "period"; //$NON-NLS-1$
		String SCHEDULE_LAST_UPDATE = "last_update"; //$NON-NLS-1$
		String SCHEDULE_STATUS = "status"; //$NON-NLS-1$
		String SCHEDULE_CREATED = "created"; //$NON-NLS-1$
		String SCHEDULE_NOTIFY_UPDATE = "notify_update"; //$NON-NLS-1$
	}

	interface LessonHistoryColumns {
		String LESSON_HISTORY_DATE = "history_date"; //$NON-NLS-1$
		String LESSON_HISTORY_START_TIME = "history_start_time"; //$NON-NLS-1$
		String LESSON_HISTORY_END_TIME = "history_end_time"; //$NON-NLS-1$
		String LESSON_HISTORY_ROOMS = "history_rooms"; //$NON-NLS-1$
	}

	interface LessonColumns extends LessonHistoryColumns {
		String LESSON_TITLE = "title"; //$NON-NLS-1$
		String LESSON_DATE = "date"; //$NON-NLS-1$
		String LESSON_START_TIME = "start_time"; //$NON-NLS-1$
		String LESSON_END_TIME = "end_time"; //$NON-NLS-1$
		String LESSON_SCHEDULE = "schedule"; //$NON-NLS-1$
		String LESSON_TYPE = "type"; //$NON-NLS-1$
		String LESSON_CHANGE = "change"; //$NON-NLS-1$
		String LESSON_CREATED = "created"; //$NON-NLS-1$
		String LESSON_ROOMS = "rooms"; //$NON-NLS-1$
		String LESSON_GROUPS = "groups"; //$NON-NLS-1$
		String LESSON_TEACHERS = "teachers"; //$NON-NLS-1$
		String LESSON_COLOR = "color"; //$NON-NLS-1$
		String LESSON_NOTE = "note"; //$NON-NLS-1$
		String LESSON_GUID = "guid"; //$NON-NLS-1$
		String LESSON_DELETED = "deleted"; //$NON-NLS-1$
		String LESSON_LAST_UPDATE = "last_update";//$NON-NLS-1$
	}

	interface ProjectColumns {
		String PROJECT_ADEWEB_ID = "project_id"; //$NON-NLS-1$
		String PROJECT_NAME = "project_name"; //$NON-NLS-1$
	}

	interface StudentNumberColumns {
		String STUDENT_NUMBER_STUDENT_NUMBER = "student_number"; //$NON-NLS-1$
		String STUDENT_NUMBER_RESOURCES = "resources"; //$NON-NLS-1$
	}

	public static class Schedule implements ScheduleColumns, BaseColumns {
		public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
				.appendPath(PATH_SCHEDULE).build();

		// public static final Uri CONTENT_WITH_PROJECT =
		// CONTENT_URI.buildUpon().appendPath(PATH_PROJECT).build() ;

		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.ade.prime.schedule"; //$NON-NLS-1$
		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.ade.prime.schedule"; //$NON-NLS-1$ 

		public static final String DEFAULT_SORT = ScheduleColumns.SCHEDULE_NAME
				+ " ASC"; //$NON-NLS-1$
	}

	public static class Lesson implements LessonColumns, BaseColumns {
		public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
				.appendPath(PATH_LESSON).build();

		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.ade.prime.lesson"; //$NON-NLS-1$
		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.ade.prime.lesson"; //$NON-NLS-1$

		public static Uri buildScheduleUri(long scheduleId) {
			return ContentUris.appendId(
					CONTENT_URI.buildUpon().appendPath(PATH_SCHEDULE),
					scheduleId).build();
		}

		public static Uri buildScheduleBetweenUri(long scheduleId,
				String start, String end) {
			return ContentUris.appendId(
					CONTENT_URI.buildUpon().appendPath(PATH_SCHEDULE)
							.appendPath(PATH_BETWEEN)
							.appendPath(Uri.encode(start))
							.appendPath(Uri.encode(end)), scheduleId).build();
		}

		public static long getScheduleId(Uri uri) {
			return Long.parseLong(uri.getPathSegments().get(3));
		}

		public static final String DEFAULT_SORT = LessonColumns.LESSON_DATE
				+ " ASC, " + LessonColumns.LESSON_START_TIME + " ASC"; //$NON-NLS-1$ //$NON-NLS-2$
	}

	public static class Project implements ProjectColumns, BaseColumns {
		public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
				.appendPath(PATH_PROJECT).build();

		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.ade.prime.project"; //$NON-NLS-1$
		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.ade.prime.project"; //$NON-NLS-1$

		public static final String DEFAULT_SORT = BaseColumns._ID + " ASC"; //$NON-NLS-1$
	}

	public static class StudentNumber implements StudentNumberColumns,
			BaseColumns {
		public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
				.appendPath(PATH_STUDENT_NUMBER).build();

		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.ade.prime.student_number"; //$NON-NLS-1$
		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.ade.prime.student_number"; //$NON-NLS-1$

		public static final String DEFAULT_SORT = BaseColumns._ID + " ASC"; //$NON-NLS-1$
	}

}// class AdeWebContract